<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta http-equiv="cache-control" content="no-cache">
<title>Genivia - The iOS plugin for developing client applications on iOS (iPhone and iPad) platforms</title>
<link href="genivia_tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="genivia_content.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="top">
 <div id="titlearea">
  <table height="72px" width="100%" cellspacing="0" cellpadding="0">
   <tbody>
    <tr>
     <td width="10%">&nbsp;</td>
     <td width="175px"><a href="http://www.genivia.com"><img alt="Genivia" src="GeniviaLogo2_trans_noslogan.png"/></a></td>
     <td class="tab_home"><a href="http://www.genivia.com">Home</a></td>
     <td class="tab_home"><a href="http://www.genivia.com/docs.html">Documentation</a></td>
     <td>
      <div style="float: right; font-size: 18px; font-weight: bold;">The iOS plugin for developing client applications on iOS (iPhone and iPad) platforms</div>
      <br>
      <div style="float: right; font-size: 10px;">updated Tue Aug 9 2016</div>
     </td>
     <td width="10%">&nbsp;</td>
    </tr>
   </tbody>
  </table>
 </div>
<!-- Generated by Doxygen 1.8.10 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">The iOS plugin for developing client applications on iOS (iPhone and iPad) platforms </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><h1><a class="anchor" id="ios_intro"></a>
Introduction</h1>
<p>Consuming Web services on iOS (iPhone and iPad) platforms is inreseasingly in demand today. However, Xcode does not have any built-in tools that make consuming Web services easy. It typically requires knowledge of XML processing techniques to send soap requests to the Web services and then parse the returning XML results. The gSOAP toolkit that provides an automated SOAP and XML data binding for C and C++ can be used directly to develop client applications to consuming Web services on iOS platforms such as iPhone and iPad. However, it's default network connection does not leverage the advantages of network connection offered by iOS SDK, instead it uses lower level TCP sockets for network connection. This soap plugin facilitates developers to develop Web services client applications on iOS platforms without maniulating the XML processing. Moreover, it takes andvantages of network connection offered by iOS SDK and supports 3G/4G, wifi etc.</p>
<p>Four Xcode examples, <a class="el" href="ios_0.html#ios_example_calc">A Simple Calculator Example (Pure C)</a> and <a class="el" href="ios_0.html#ios_example_geoip">A GeoIPService (C++)</a> can be found in samples/ios.</p>
<h1><a class="anchor" id="ios_1"></a>
Getting Started</h1>
<p>To start building Web services client applications for iPhone and/or iPad with gSOAP , you need:</p>
<ul>
<li>The gSOAP package from <a href="http://www.genivia.com/Products/downloads.html">http://www.genivia.com/Products/downloads.html</a> (select gSOAP toolkit standard edition from the list of software packages), and</li>
</ul>
<ul>
<li>Xcode IDE with the iOS SDK installed.</li>
</ul>
<p>Development of Web services applications on iOS is no different from the development SOAP Web services applications on Linux, Unix and Mac OS except with a soap plugin registration. Specifically, there are four steps to develop SOAP Web services client applications on iOS:</p>
<ul>
<li>Generating application stubs using the gSOAP toolkit and add the source files</li>
</ul>
<ul>
<li>Creating an iOS application project to the Xcode project</li>
</ul>
<ul>
<li>Registering the iOS plugin</li>
</ul>
<ul>
<li>Calling service methods</li>
</ul>
<h2><a class="anchor" id="iso_register_pulg"></a>
Registering iOS Plugin (Required)</h2>
<p>To register the iOS plugin, simply call <em>soap_register_plugin</em> method:</p>
<div class="fragment"><div class="line"><span class="preprocessor">#import &quot;<a class="code" href="gsoapios_8h.html">gsoapios.h</a>&quot;</span></div>
<div class="line"></div>
<div class="line"><span class="keyword">struct </span>soap *soap = soap_new();</div>
<div class="line">soap_register(soap, <a class="code" href="gsoapios_8h.html#aa05f43296a215eae65d5d43dc88620ff">soap_ios</a>); <span class="comment">// Register the iOS plugin</span></div>
<div class="line">...</div>
<div class="line">soap_end(soap);  <span class="comment">// Clean up temporaries</span></div>
<div class="line">soap_destroy(soap); <span class="comment">// Free soap context</span></div>
</div><!-- fragment --><p>The plugin is destroyed automatically by the soap context when the soap_end method is executed.</p>
<h2><a class="anchor" id="ios_cache_policy"></a>
Specifying Cache policy (Optional)</h2>
<p>The interaction beween the client and the Web servcie server can be controled by specifying the cache policy. To specify the cache policy, call the method <em><a class="el" href="gsoapios_8mm.html#a0dd8ddc18b78e14e9978a1369f02d97c" title="Sets cache policy The constants used to specify interaction with the cached responses are: ...">soap_ios_setcachepolicy(struct soap *soap, unsigned int policy)</a> </em>. The method cannot be called before the pluging is registered.</p>
<div class="fragment"><div class="line"><span class="preprocessor">#import &quot;<a class="code" href="gsoapios_8h.html">gsoapios.h</a>&quot;</span></div>
<div class="line"></div>
<div class="line"><span class="keyword">struct </span>soap *soap = soap_new();</div>
<div class="line">soap_register(soap, <a class="code" href="gsoapios_8h.html#aa05f43296a215eae65d5d43dc88620ff">soap_ios</a>); <span class="comment">// Register the iOS plugin</span></div>
<div class="line"></div>
<div class="line"><span class="comment">// Specify the cache policy for the request </span></div>
<div class="line"><span class="comment">// Caveat: this method cannot be called before the plugin is registered</span></div>
<div class="line"><span class="comment">// If this method is not called, the cache policy is set to NSURLRequestUseProtocolCachePolicy (0) by default.</span></div>
<div class="line">soap_ios_setchacepolicy(soap, NSURLRequestReturnCacheDataElseLoad); <span class="comment">// (2)</span></div>
<div class="line"><span class="comment">// Or use the integer directly instead of enum</span></div>
<div class="line"><span class="comment">// soap_ios_setchacepolicy(soap, 2); // (NSURLRequestReturnCacheDataElseLoad)</span></div>
<div class="line"></div>
<div class="line">...</div>
<div class="line">soap_end(soap);  <span class="comment">// clean up allocated temporaries </span></div>
<div class="line">soap_destroy(soap); <span class="comment">// Free soap context</span></div>
</div><!-- fragment --><p>The available cache policies that can be specified are: </p><div class="fragment"><div class="line"><span class="keyword">enum</span> {</div>
<div class="line">       NSURLRequestUseProtocolCachePolicy = 0,</div>
<div class="line">       NSURLRequestReloadIgnoringLocalCacheData = 1,</div>
<div class="line">       NSURLRequestReloadIgnoringCacheData = NSURLRequestReloadIgnoringLocalCacheData,</div>
<div class="line">       NSURLRequestReturnCacheDataElseLoad = 2,</div>
<div class="line">       NSURLRequestReturnCacheDataDontLoad = 3,</div>
<div class="line">       NSURLRequestReloadIgnoringLocalAndRemoteCacheData =4,</div>
<div class="line">       NSURLRequestReloadRevalidatingCacheData = 5</div>
<div class="line">}</div>
</div><!-- fragment --><p>If this method is not called, the cache policy is set to NSURLRequestUseProtocolCachePolicy (0) by default.</p>
<h2><a class="anchor" id="ios_timeout_interval"></a>
Specifying Timeout Interval (Optional)</h2>
<p>The timeout interval for network connection can be specified using the method <em><a class="el" href="gsoapios_8mm.html#a733a36a9b2649b17ba7693fc7cb25325" title="Sets timeout interval. ">soap_ios_settimeoutinterval(struct soap *soap, double seconds)</a></em>. The method cannot be called before the pluging is registered. If this method is not called, the timeout interval is 60 seconds by default.</p>
<div class="fragment"><div class="line"><span class="preprocessor">#import &quot;<a class="code" href="gsoapios_8h.html">gsoapios.h</a>&quot;</span></div>
<div class="line"></div>
<div class="line"><span class="keyword">struct </span>soap *soap = soap_new();</div>
<div class="line">soap_register(soap, <a class="code" href="gsoapios_8h.html#aa05f43296a215eae65d5d43dc88620ff">soap_ios</a>); <span class="comment">// Register the iOS plugin</span></div>
<div class="line"></div>
<div class="line"><span class="comment">// Specify the timout interval in terms of seconds </span></div>
<div class="line"><span class="comment">// If this method is not called, the timeout interval is set to 60 seconds by default</span></div>
<div class="line"><span class="comment">// Caveat: this method cannot be called before the plugin is registered</span></div>
<div class="line"><a class="code" href="gsoapios_8h.html#a9d918af8606bf15e7be4eb237fe3421b">soap_ios_settimeoutinterval</a>(soap, 30.0);</div>
<div class="line"></div>
<div class="line">...</div>
<div class="line">soap_end(soap);</div>
<div class="line">soap_destroy(soap);</div>
</div><!-- fragment --><h2><a class="anchor" id="ios_http_auth"></a>
Handling HTTP Authentication</h2>
<p>A server may request user authentication and deny access (HTTP 401 error) when the client tries to connect without HTTP authentication (or with the wrong authentication information).</p>
<p>HTTP authentication (basic) is enabled at the client-side by setting the soap.userid and soap.passwd strings to a username and password, respectively.</p>
<p>Be aware of that both of userid and password must be set in pair, that is, if one of them is set, the other must be set too.</p>
<p>If the server requires basic HTTP authentication, for example, the userid and password can be specified:</p>
<div class="fragment"><div class="line"><span class="keyword">struct </span>soap *soap = soap_new();</div>
<div class="line">soap-&gt;userid = <span class="stringliteral">&quot;someone&quot;</span>;</div>
<div class="line">soap-&gt;passwd = <span class="stringliteral">&quot;somepass&quot;</span>;</div>
<div class="line">...</div>
<div class="line">soap_end(soap); <span class="comment">// Clean up temporaries</span></div>
<div class="line">soap_destroy(soap);</div>
</div><!-- fragment --><h1><a class="anchor" id="ios_example"></a>
Examples</h1>
<p>This section intoduces two examples to demonstrate the development of client applications consuming SOAP Web services on iOS platforms (iPhone and iPad) using gSOAP tools and the iOS plugin. Because gSOAP supports development for both pure C and C++, the first example, <a class="el" href="ios_0.html#ios_example_calc">A Simple Calculator Example (Pure C)</a>, is developed using pure C. The second one, <a class="el" href="ios_0.html#ios_example_geoip">A GeoIPService (C++)</a>, is developmed using C++.</p>
<p>We assume you already have had the expereince in development of applications for iPhone and iPad using Xcode with iOS SDK installed.</p>
<p>It is crucial to follow these directions in order for your app to work:</p>
<ul>
<li>Rename the <em>.m</em> files to <em>.mm</em> files. The iOS plugin implementation file <em>gsoapios.m</em> must be renamed to <em><a class="el" href="gsoapios_8mm.html">gsoapios.mm</a></em>. The <em>main.m</em> must be renamed to <em>main.mm</em>. Other files such as your <a class="el" href="interface_view_controller.html">ViewController</a> may also be renamed with <em>.mm</em>.</li>
</ul>
<ul>
<li>Generate C++ proxy using proper options with <em>wsdl2h</em> and <em>soapcpp2</em></li>
</ul>
<ul>
<li>Use the <em>stdsoap2.cpp</em> instead of <em>stdsoap2.c</em> from the gSOAP package in your iOS project.</li>
</ul>
<h2><a class="anchor" id="ios_example_calc"></a>
A Simple Calculator Example (Pure C)</h2>
<p>This example shows you how to develop a client application in C using gSOAP and the ios plugin, which consumes a simple caculator service on iOS using gSOAP. The simple calculator service was developed and deployed as a demo using the gSOAP tools (refer to <a href="http://www.genivia.com/Products/gsoap/demos/index.html">http://www.genivia.com/Products/gsoap/demos/index.html</a> for details). The gSOAP Calculator Service provides several operations such as <em>add</em>, <em>sub</em>, <em>mul</em>, <em>div</em> etc. In this example, we use operation <em>add</em> as a demo. Other operations are alled in a similar way. The <em>wsdl</em> file for this service can be obtained at the following link: <a href="http://www.genivia.com/calc.wsdl">http://www.genivia.com/calc.wsdl</a></p>
<p>The Xcode project for this example can be found in samples/ios/calc.</p>
<h3><a class="anchor" id="ios_calc_step_1"></a>
Step 1: Generating stubs for C API</h3>
<p>To generate codes for the calculator Web service, we first run the <em>wsdl2h</em> tool from the command line on the URL of the WSDL and use option <em>-o</em> to specify the output file (Alternatively, you can download the <em>calc.wsdl</em> and use the local file instead of the URL):</p>
<div class="fragment"><div class="line">&gt; wsdl2h -o calc.h http:<span class="comment">//www.genivia.com/calc.wsdl</span></div>
</div><!-- fragment --><p>This generates the <em>calc.h</em> service definition header file with service operation definitions and types for the operation's data. By default, gSOAP assumes you will use C++ with STL.</p>
<p>We have not yet generated the stubs for the CAPI. To do so, run the <em>soapcpp2</em> compiler:</p>
<div class="fragment"><div class="line">&gt; soapcpp2 -j -CL -I /path/to/import calc.h</div>
</div><!-- fragment --><p>Option <em>-CL</em> indicates client-side only files (<em>soapcpp2</em> generates both client and server stubs and skeletons by default). This generates a number of source files for client application development.</p>
<h3><a class="anchor" id="ios_calc_step_2"></a>
Step 2: Creating Xcode project for iPhone</h3>
<p>Launch the Xcode, create a View-based Application project and name it <em>Calc</em>. Open the <em>CalcViewController.xib</em> file in the Interface Builder. Double-click on the View item and populate it with the views listed below and shown in Figure 1:</p>
<ul>
<li>Two Labels ("+" and "A Simple Calculator") </li>
<li>Two Text Fields (operand1 and operand2) </li>
<li>One Round Rect Button ("+" button)</li>
</ul>
<div class="image">
<img src="calc-view.png" alt="calc-view.png"/>
<div class="caption">
Figure 1. View of the Calculator Web Service Client</div></div>
<p> In Xcode, edit the file <em>CalcViewController.h</em> to make it look like the following:</p>
<div class="fragment"><div class="line"><span class="comment">// File: CalcViewController.h</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#import &lt;UIKit/UIKit.h&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="keyword">@interface </span><a class="code" href="interface_view_controller.html">ViewController</a> : UIViewController {</div>
<div class="line">UITextField *op1; <span class="comment">// operand1</span></div>
<div class="line">UITextField *op2; <span class="comment">// operand2</span></div>
<div class="line"></div>
<div class="line">}</div>
<div class="line"><span class="keyword">@property</span> (nonatomic, retain) IBOutlet UITextField *op1;</div>
<div class="line"><span class="keyword">@property</span> (nonatomic, retain) IBOutlet UITextField *op2;</div>
<div class="line"></div>
<div class="line">- (IBAction) buttonPressed;</div>
<div class="line"><span class="keyword">@end</span></div>
</div><!-- fragment --><p>Link the op1 and op2 to the two Text Fields and delegate the button action to method buttonPressed.</p>
<h3><a class="anchor" id="ios_calc_step_3"></a>
Step 3: Adding generated source stubs to the Xcode project</h3>
<p>Add the source files <em>soapC.cpp</em>, <em>soapClient.cpp</em>, <em>soapH.h</em>, and <em>soapStub.h</em> generated in <a class="el" href="ios_0.html#ios_calc_step_1">Step 1: Generating stubs for C API</a> to the project. Also add files <em>stdsoap2.h</em> and <em>stdsoap2.cpp</em> to the project from gsoap package as well as the iOS pluhin files <em><a class="el" href="gsoapios_8h.html">gsoapios.h</a></em> and <em>sgsoapios.mm</em>.</p>
<p>Once all of your files have been added to the project, ensure they are all of type "Objective C++ Source". This ensures that there will be no issues with mixing Objective C and C++ code.</p>
<p>In Xcode, edit the file <em>info.plist</em> to make it look like the following:</p>
<div class="fragment"><div class="line">&lt;?xml version=<span class="stringliteral">&quot;1.0&quot;</span> encoding=<span class="stringliteral">&quot;UTF-8&quot;</span>?&gt;</div>
<div class="line">&lt;!DOCTYPE plist PUBLIC <span class="stringliteral">&quot;-//Apple//DTD PLIST 1.0//EN&quot;</span> <span class="stringliteral">&quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;</span>&gt;</div>
<div class="line">&lt;plist version=<span class="stringliteral">&quot;1.0&quot;</span>&gt;</div>
<div class="line">&lt;dict&gt;</div>
<div class="line">&lt;key&gt;NSAppTransportSecurity&lt;/key&gt;</div>
<div class="line">&lt;dict&gt;</div>
<div class="line">&lt;key&gt;NSAllowsArbitraryLoads&lt;/key&gt;</div>
<div class="line">&lt;<span class="keyword">true</span>/&gt;</div>
<div class="line">&lt;/dict&gt;</div>
<div class="line">       &lt;key&gt;CFBundleDevelopmentRegion&lt;/key&gt;</div>
<div class="line">       &lt;<span class="keywordtype">string</span>&gt;en&lt;/<span class="keywordtype">string</span>&gt;</div>
<div class="line">       &lt;key&gt;CFBundleExecutable&lt;/key&gt;</div>
<div class="line">       &lt;<span class="keywordtype">string</span>&gt;$(EXECUTABLE_NAME)&lt;/<span class="keywordtype">string</span>&gt;</div>
<div class="line">       &lt;key&gt;CFBundleIdentifier&lt;/key&gt;</div>
<div class="line">       &lt;<span class="keywordtype">string</span>&gt;$(PRODUCT_BUNDLE_IDENTIFIER)&lt;/<span class="keywordtype">string</span>&gt;</div>
<div class="line">       &lt;key&gt;CFBundleInfoDictionaryVersion&lt;/key&gt;</div>
<div class="line">       &lt;<span class="keywordtype">string</span>&gt;6.0&lt;/<span class="keywordtype">string</span>&gt;</div>
<div class="line">       &lt;key&gt;CFBundleName&lt;/key&gt;</div>
<div class="line">       &lt;<span class="keywordtype">string</span>&gt;$(PRODUCT_NAME)&lt;/<span class="keywordtype">string</span>&gt;</div>
<div class="line">       &lt;key&gt;CFBundlePackageType&lt;/key&gt;</div>
<div class="line">       &lt;<span class="keywordtype">string</span>&gt;APPL&lt;/string&gt;</div>
<div class="line">       &lt;key&gt;CFBundleShortVersionString&lt;/key&gt;</div>
<div class="line">       &lt;<span class="keywordtype">string</span>&gt;1.0&lt;/<span class="keywordtype">string</span>&gt;</div>
<div class="line">       &lt;key&gt;CFBundleSignature&lt;/key&gt;</div>
<div class="line">       &lt;<span class="keywordtype">string</span>&gt;????&lt;/<span class="keywordtype">string</span>&gt;</div>
<div class="line">       &lt;key&gt;CFBundleVersion&lt;/key&gt;</div>
<div class="line">       &lt;<span class="keywordtype">string</span>&gt;1&lt;/<span class="keywordtype">string</span>&gt;</div>
<div class="line">       &lt;key&gt;LSRequiresIPhoneOS&lt;/key&gt;</div>
<div class="line">       &lt;<span class="keyword">true</span>/&gt;</div>
<div class="line">       &lt;key&gt;UILaunchStoryboardName&lt;/key&gt;</div>
<div class="line">       &lt;<span class="keywordtype">string</span>&gt;LaunchScreen&lt;/string&gt;</div>
<div class="line">       &lt;key&gt;UIMainStoryboardFile&lt;/key&gt;</div>
<div class="line">       &lt;<span class="keywordtype">string</span>&gt;Main&lt;/string&gt;</div>
<div class="line">       &lt;key&gt;UIRequiredDeviceCapabilities&lt;/key&gt;</div>
<div class="line">       &lt;array&gt;</div>
<div class="line">&lt;<span class="keywordtype">string</span>&gt;armv7&lt;/string&gt;</div>
<div class="line">       &lt;/array&gt;</div>
<div class="line">       &lt;key&gt;UISupportedInterfaceOrientations&lt;/key&gt;</div>
<div class="line">       &lt;array&gt;</div>
<div class="line">&lt;<span class="keywordtype">string</span>&gt;UIInterfaceOrientationPortrait&lt;/string&gt;</div>
<div class="line">&lt;<span class="keywordtype">string</span>&gt;UIInterfaceOrientationLandscapeLeft&lt;/string&gt;</div>
<div class="line">&lt;<span class="keywordtype">string</span>&gt;UIInterfaceOrientationLandscapeRight&lt;/string&gt;</div>
<div class="line">       &lt;/array&gt;</div>
<div class="line">&lt;/dict&gt;</div>
<div class="line">&lt;/plist&gt;</div>
<div class="line"><span class="keyword">@end</span> code</div>
<div class="line"></div>
<div class="line">These changes ensure that you cna access the web services despite the added layer of protection.</div>
<div class="line"></div>
<div class="line">@subsubsection ios_calc_step_4 Step 4: Implementing the Logic by calling the soap service</div>
<div class="line"></div>
<div class="line">Firstly, edit file &lt;i&gt;main.mm&lt;/i&gt; to <span class="keyword">import</span> the file &lt;i&gt;./Classes/calc.nsmap&lt;/i&gt;.</div>
<div class="line">Link errors may arise without importing <span class="keyword">this</span> <span class="keyword">namespace</span> mapping.</div>
<div class="line"></div>
<div class="line">@code</div>
<div class="line"><span class="comment">// File: main.mm</span></div>
<div class="line"></div>
<div class="line">#import &lt;UIKit/UIKit.h&gt;</div>
<div class="line">#<span class="keyword">import</span> <span class="stringliteral">&quot;../../calc.nsmap&quot;</span></div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> * argv[]) {</div>
<div class="line">   @autoreleasepool {</div>
<div class="line">   <span class="keywordflow">return</span> UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate <span class="keyword">class</span>]));}</div>
<div class="line">}</div>
</div><!-- fragment --><p>Then, implememt the source file <em>CalcViewController.mm</em> as the following:</p>
<div class="fragment"><div class="line"><span class="comment">//</span></div>
<div class="line"><span class="comment">//  ViewController.mm</span></div>
<div class="line"><span class="comment">//  calc</span></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"><span class="comment">//  Created by Bethany Sanders on 7/11/16.</span></div>
<div class="line"><span class="comment">//  Copyright © 2016 Bethany Sanders. All rights reserved.</span></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#import &quot;ViewController.h&quot;</span></div>
<div class="line"><span class="preprocessor">#import &quot;soapStub.h&quot;</span></div>
<div class="line"><span class="preprocessor">#import &quot;<a class="code" href="gsoapios_8h.html">gsoapios.h</a>&quot;</span></div>
<div class="line"></div>
<div class="line"><span class="keyword">@implementation </span><a class="code" href="interface_view_controller.html">ViewController</a></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="keyword">@synthesize</span> op1; <span class="comment">// Set or get opreand1</span></div>
<div class="line"><span class="keyword">@synthesize</span> op2; <span class="comment">// Set or get opreand1</span></div>
<div class="line"></div>
<div class="line">- (IBAction) buttonPressed</div>
<div class="line">{</div>
<div class="line">   <span class="keywordtype">double</span> x = [op1.text doubleValue];</div>
<div class="line">   <span class="keywordtype">double</span> y = [op2.text doubleValue];</div>
<div class="line"></div>
<div class="line">   <span class="keyword">struct </span>soap *soap = soap_new1(SOAP_IO_DEFAULT|SOAP_IO_KEEPALIVE|SOAP_XML_INDENT|SOAP_XML_STRICT);</div>
<div class="line"></div>
<div class="line">   <span class="keywordflow">if</span> (soap_register_plugin(soap, <a class="code" href="gsoapios_8h.html#aa05f43296a215eae65d5d43dc88620ff">soap_ios</a>) == SOAP_OK) {</div>
<div class="line">       <span class="comment">// Specify the timeout interval (optional) to 45 seconds instead of</span></div>
<div class="line">       <span class="comment">// the default 60 seconds</span></div>
<div class="line">       <a class="code" href="gsoapios_8h.html#a9d918af8606bf15e7be4eb237fe3421b">soap_ios_settimeoutinterval</a>(soap, 45.0);</div>
<div class="line"></div>
<div class="line">       <span class="keywordtype">double</span> result;</div>
<div class="line"></div>
<div class="line">       <span class="comment">// Call Web service operation add</span></div>
<div class="line">       <span class="keywordtype">int</span> status = soap_call_ns2__add(soap, NULL, NULL,x, y, result);</div>
<div class="line"></div>
<div class="line">       soap_free_temp(soap); <span class="comment">// Cleanup temporary resources</span></div>
<div class="line"></div>
<div class="line">       <span class="comment">// Check soap response status</span></div>
<div class="line">       <span class="keywordflow">if</span> (status == SOAP_OK) {</div>
<div class="line"></div>
<div class="line">           NSString *resultString;</div>
<div class="line">           NSString *titleString;</div>
<div class="line"></div>
<div class="line">           resultString = [NSString stringWithFormat:@&quot;%f&quot;,result];</div>
<div class="line">           titleString = [NSString stringWithFormat:@&quot;%f + %f =&quot;,x, y];</div>
<div class="line"></div>
<div class="line">           <span class="comment">// Show the result in an alert</span></div>
<div class="line">           UIAlertController * alert = [UIAlertController</div>
<div class="line">               alertControllerWithTitle:titleString</div>
<div class="line">               message:resultString</div>
<div class="line">               preferredStyle:UIAlertControllerStyleAlert];</div>
<div class="line">           UIAlertAction* cancelButton = [UIAlertAction</div>
<div class="line">               actionWithTitle:@&quot;OK&quot;</div>
<div class="line">               style:UIAlertActionStyleDefault</div>
<div class="line">               handler:^(UIAlertAction * action){}];</div>
<div class="line"></div>
<div class="line">           [alert addAction: cancelButton];</div>
<div class="line">           [<span class="keyword">self</span> presentViewController:alert animated:YES completion:nil];</div>
<div class="line">}</div>
<div class="line"><span class="keywordflow">else</span></div>
<div class="line">   soap_print_fault(soap,stderr); <span class="comment">// Print soap error in console</span></div>
<div class="line">}</div>
<div class="line"></div>
<div class="line">soap_destroy(soap);     <span class="comment">//free soap</span></div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keyword">@end</span></div>
</div><!-- fragment --><p>A screen snapshot of the client is shown in Figure 2.</p>
<div class="image">
<img src="calc-result.png" alt="calc-result.png"/>
<div class="caption">
Figure 2: Snapshot of the CalcViewService result</div></div>
<h2><a class="anchor" id="ios_example_geoip"></a>
A GeoIPService (C++)</h2>
<p>GeoIPService is a live SOAP Web service that enables you to look up contries by IP address or by Context.</p>
<p>This example shows you how to develop a client application in C++ using gSOAP and the ios plugin, which consumes the GeoIPSerive on iOS using gSOAP. The WSDL file for this servive can be downloaded at the following link: <a href="http://www.webservicex.net/geoipservice.asmx?WSDL">http://www.webservicex.net/geoipservice.asmx?WSDL</a></p>
<p>It is crucial to follow these directions in order for your app to work:</p>
<ul>
<li>Rename the <em>.m</em> files to <em>.mm</em> files. The iOS plugin implementation file <em>gsoapios.m</em> must be renamed to <em><a class="el" href="gsoapios_8mm.html">gsoapios.mm</a></em>. The <em>main.m</em> must be renamed to <em>main.mm</em>. Other files such as your <a class="el" href="interface_view_controller.html">ViewController</a> may also be renamed with <em>.mm</em>.</li>
</ul>
<ul>
<li>Generate C++ proxy using proper options with <em>wsdl2h</em> and <em>soapcpp2</em></li>
</ul>
<ul>
<li>Use the <em>stdsoap2.cpp</em> instead of <em>stdsoap2.c</em> from the gSOAP package in your iOS project.</li>
</ul>
<p>The Xcode project for this example can be found in samples/ios/GeoIPService.</p>
<h3><a class="anchor" id="ios_geoip_step_1"></a>
Step 1: Generating stubs for C++ Proxy</h3>
<p>To generate codes for the GeoIPSerbice Web service, we first run the <em>wsdl2h</em> tool from the command line on the URL of the WSDL and use option <em>-o</em> to specify the output file (Alternatively, you can download the <em>GeoIPService.wsdl</em> file and use the local file instead of the URL):</p>
<div class="fragment"><div class="line">&gt;wsdl2h -o GeoIPService.h http:<span class="comment">//www.webservicex.net/geoipservice.asmx?WSDL</span></div>
</div><!-- fragment --><p>This generates the <em>GeoIPService.h</em> service definition header file with service operation definitions and types for the operation's data. By default, gSOAP assumes you will use C++ with STL.</p>
<p>To generate the stubs for the C++ proxy classes, run the <em>soapcpp2</em> compiler:</p>
<div class="fragment"><div class="line">&gt;soapcpp2 -j -CL -I$GSOAP_HOME/import GeoIPService.h</div>
</div><!-- fragment --><p>Option <em>-j</em> tells the compiler to generate C++ proxy and option <em>-CL</em> indicates client-side only files (<em>soapcpp2</em> generates both client and server stubs and skeletons by default). Option -I is needed to import the <em>stlvector.h</em> file from the import directory in the gSOAP package to support serialization of STL vectors.</p>
<h3><a class="anchor" id="ios_geoip_step_2"></a>
Step 2: Creating Xcode project for iPhone</h3>
<p>Create a View-based Application project and name it <em>GeoIPService</em> and rename the <em>.m</em> source files to <em>.mm</em>. Open the <em>GeoIPserviceViewController.xib</em> file in the Interface Builder. Double-click on the View item and populate it with the views listed below and shown in Figure 3:</p>
<ul>
<li>A Label ("IP Address") </li>
<li>A Text Field </li>
<li>One Round Rect Button ("Find Country" button)</li>
</ul>
<div class="image">
<img src="geoip-view.png" alt="geoip-view.png"/>
<div class="caption">
Figure 3. View of the GeoIPService Client</div></div>
<p> In Xcode, edit the file <em>GeoIPServiceViewController.h</em> to make it look like the following:</p>
<div class="fragment"><div class="line"><span class="comment">// File: GeoIPServiceViewController.h</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#import &lt;UIKit/UIKit.h&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="keyword">@interface </span><a class="code" href="interface_view_controller.html">ViewController</a> : UIViewController{</div>
<div class="line">UITextField* IPAddress;</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keyword">@property</span> (strong, nonatomic) IBOutlet UITextField *IPAddress;</div>
<div class="line"></div>
<div class="line">- (IBAction) buttonPressed;</div>
<div class="line"><span class="keyword">@end</span></div>
</div><!-- fragment --><p>Set the ipAddress outlet and the buttonFindCountry:(id)sender method to delegate action of the button.</p>
<p>In Xcode, edit the file <em>info.plist</em> to make it look like the following:</p>
<div class="fragment"><div class="line">&lt;?xml version=<span class="stringliteral">&quot;1.0&quot;</span> encoding=<span class="stringliteral">&quot;UTF-8&quot;</span>?&gt;</div>
<div class="line">&lt;!DOCTYPE plist PUBLIC <span class="stringliteral">&quot;-//Apple//DTD PLIST 1.0//EN&quot;</span> <span class="stringliteral">&quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;</span>&gt;</div>
<div class="line">&lt;plist version=<span class="stringliteral">&quot;1.0&quot;</span>&gt;</div>
<div class="line">&lt;dict&gt;</div>
<div class="line">&lt;key&gt;NSAppTransportSecurity&lt;/key&gt;</div>
<div class="line">&lt;dict&gt;</div>
<div class="line">&lt;key&gt;NSAllowsArbitraryLoads&lt;/key&gt;</div>
<div class="line">&lt;<span class="keyword">true</span>/&gt;</div>
<div class="line">&lt;/dict&gt;</div>
<div class="line">       &lt;key&gt;CFBundleDevelopmentRegion&lt;/key&gt;</div>
<div class="line">       &lt;<span class="keywordtype">string</span>&gt;en&lt;/<span class="keywordtype">string</span>&gt;</div>
<div class="line">       &lt;key&gt;CFBundleExecutable&lt;/key&gt;</div>
<div class="line">       &lt;<span class="keywordtype">string</span>&gt;$(EXECUTABLE_NAME)&lt;/<span class="keywordtype">string</span>&gt;</div>
<div class="line">       &lt;key&gt;CFBundleIdentifier&lt;/key&gt;</div>
<div class="line">       &lt;<span class="keywordtype">string</span>&gt;$(PRODUCT_BUNDLE_IDENTIFIER)&lt;/<span class="keywordtype">string</span>&gt;</div>
<div class="line">       &lt;key&gt;CFBundleInfoDictionaryVersion&lt;/key&gt;</div>
<div class="line">       &lt;<span class="keywordtype">string</span>&gt;6.0&lt;/<span class="keywordtype">string</span>&gt;</div>
<div class="line">       &lt;key&gt;CFBundleName&lt;/key&gt;</div>
<div class="line">       &lt;<span class="keywordtype">string</span>&gt;$(PRODUCT_NAME)&lt;/<span class="keywordtype">string</span>&gt;</div>
<div class="line">       &lt;key&gt;CFBundlePackageType&lt;/key&gt;</div>
<div class="line">       &lt;<span class="keywordtype">string</span>&gt;APPL&lt;/string&gt;</div>
<div class="line">       &lt;key&gt;CFBundleShortVersionString&lt;/key&gt;</div>
<div class="line">       &lt;<span class="keywordtype">string</span>&gt;1.0&lt;/<span class="keywordtype">string</span>&gt;</div>
<div class="line">       &lt;key&gt;CFBundleSignature&lt;/key&gt;</div>
<div class="line">       &lt;<span class="keywordtype">string</span>&gt;????&lt;/<span class="keywordtype">string</span>&gt;</div>
<div class="line">       &lt;key&gt;CFBundleVersion&lt;/key&gt;</div>
<div class="line">       &lt;<span class="keywordtype">string</span>&gt;1&lt;/<span class="keywordtype">string</span>&gt;</div>
<div class="line">       &lt;key&gt;LSRequiresIPhoneOS&lt;/key&gt;</div>
<div class="line">       &lt;<span class="keyword">true</span>/&gt;</div>
<div class="line">       &lt;key&gt;UILaunchStoryboardName&lt;/key&gt;</div>
<div class="line">       &lt;<span class="keywordtype">string</span>&gt;LaunchScreen&lt;/string&gt;</div>
<div class="line">       &lt;key&gt;UIMainStoryboardFile&lt;/key&gt;</div>
<div class="line">       &lt;<span class="keywordtype">string</span>&gt;Main&lt;/string&gt;</div>
<div class="line">       &lt;key&gt;UIRequiredDeviceCapabilities&lt;/key&gt;</div>
<div class="line">       &lt;array&gt;</div>
<div class="line">&lt;<span class="keywordtype">string</span>&gt;armv7&lt;/string&gt;</div>
<div class="line">       &lt;/array&gt;</div>
<div class="line">       &lt;key&gt;UISupportedInterfaceOrientations&lt;/key&gt;</div>
<div class="line">       &lt;array&gt;</div>
<div class="line">&lt;<span class="keywordtype">string</span>&gt;UIInterfaceOrientationPortrait&lt;/string&gt;</div>
<div class="line">&lt;<span class="keywordtype">string</span>&gt;UIInterfaceOrientationLandscapeLeft&lt;/string&gt;</div>
<div class="line">&lt;<span class="keywordtype">string</span>&gt;UIInterfaceOrientationLandscapeRight&lt;/string&gt;</div>
<div class="line">       &lt;/array&gt;</div>
<div class="line">&lt;/dict&gt;</div>
<div class="line">&lt;/plist&gt;</div>
<div class="line"><span class="keyword">@end</span> code</div>
<div class="line"></div>
<div class="line">These changes ensure that you cna access the web services despite the added layer of protection.</div>
<div class="line"></div>
<div class="line">@subsubsection ios_geoip_step_3 Step 3: Adding generated source stubs to the Xcode project</div>
<div class="line"></div>
<div class="line">Add the source files &lt;i&gt;soapC.cpp&lt;/i&gt;, &lt;i&gt;GeoIPServiceSoap12Proxy.cpp&lt;/i&gt;, </div>
<div class="line">&lt;i&gt;GeoIPServiceSoap12Proxy.h&lt;/i&gt;, &lt;i&gt;soapH.h&lt;/i&gt;, </div>
<div class="line">and&lt;i&gt;soapStub.h&lt;/i&gt; generated in @ref ios_geoip_step_1 to the project. Also </div>
<div class="line">add files&lt;i&gt;stdsoap2.h&lt;/i&gt; and &lt;i&gt;stdsoap2.cpp&lt;/i&gt; to the project from gsoap</div>
<div class="line">package and the iOS pluhin files &lt;i&gt;gsoapios.h&lt;/i&gt; and &lt;i&gt;sgsoapios.m&lt;/i&gt;.</div>
<div class="line">Do not forget to rename the &lt;i&gt;sgsoapios.m&lt;/i&gt; to &lt;i&gt;sgsoapios.mm&lt;/i&gt;</div>
<div class="line"></div>
<div class="line">The &lt;i&gt;GeoIPServiceSoap12Proxy.h&lt;/i&gt; and &lt;i&gt;GeoIPServiceSoap12Proxy.cpp&lt;/i&gt; </div>
<div class="line">are C++ proxy header and implementation files <span class="keywordflow">for</span> SOAP 1.2 (You may use </div>
<div class="line">&lt;i&gt;GeoIPServiceSoapProxy.cpp&lt;/i&gt; and &lt;i&gt;GeoIPServiceSoapProxy.h&lt;/i&gt;</div>
<div class="line"><span class="keywordflow">for</span> SOAP1.1). </div>
<div class="line"></div>
<div class="line">@subsubsection ios_geoip_step_4 Step 4: Implementing the Logic by calling the soap service</div>
<div class="line"></div>
<div class="line">Firstly, edit file &lt;i&gt;main.mm&lt;/i&gt; to <span class="keyword">import</span> the file</div>
<div class="line">&lt;i&gt;./Classes/GeoIPService.nsmap&lt;/i&gt;. Link errors would arise without importing</div>
<div class="line"><span class="keyword">this</span> <span class="keyword">namespace </span>mapping.</div>
<div class="line"></div>
<div class="line">@code</div>
<div class="line"><span class="comment">// File: main.mm</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#import &lt;UIKit/UIKit.h&gt;</span></div>
<div class="line"><span class="preprocessor">#import &quot;AppDelegate.h&quot;</span></div>
<div class="line"><span class="preprocessor">#include &quot;../../GeoIPServiceSoap.nsmap&quot;</span></div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> * argv[]) {</div>
<div class="line">   @autoreleasepool {</div>
<div class="line">   <span class="keywordflow">return</span> UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate <span class="keyword">class</span>]));}</div>
<div class="line">}</div>
<div class="line">} </div>
</div><!-- fragment --><p>Then, implememt the source file <em>GeoIPServiceViewController.mm</em> as the following:</p>
<p>ViewController.mm calc</p>
<p>Created by Bethany Sanders on 7/11/16. Copyright © 2016 Bethany Sanders. All rights reserved.</p>
<p>#import "ViewController.h" #include "soapGeoIPServiceSoapProxy.h" #import "soapStub.h" #import "gsoapios.h" using namespace std; </p>
</div></div><!-- contents -->
<hr class="footer">
<address class="footer">
Copyright (C) 2016, Robert van Engelen, Genivia Inc., All Rights Reserved.
</address>
<address class="footer"><small>
Converted on Tue Aug 9 2016 15:04:41 by <a target="_blank" href="http://www.doxygen.org/index.html">Doxygen</a> 1.8.10</small></address>
<br>
<div style="height: 246px; background: #DBDBDB;">
</body>
</html>
